<div class="title ui-corner-all"> 
<?= $this->viewParams['type']?> list
<? if ($this->viewParams['type'] != "post" && $this->viewParams['type'] != "gallery") :?>
in order of appearance
<? endif?>
</div>


<div>
<? if ($this->viewParams['type'] != "post" && $this->viewParams['type'] != "gallery") :?>
Drag and drop to set the order of appearance:
<?endif?>
<br/><br/>
<ul id="sortable" class="ui-corner-all" style="width: 98%">
<? foreach ($this->viewParams['result'] as $member) :?>
	<li class="ui-state-default" id="nodeid_<?= $member['id']?>">
	<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
	<?if ($this->viewParams['type'] == "project") :?>
	- <a href="/vi/archin/master/search?type=project&category=<?=$member['category']?>"><?= archin_category_name_from_index($member['category'])?></a> |	
      <a href="/vi/archin/master/gallery?type=project&id=<?=$member['id']?>">gallery</a> |	
	<?endif?>
	<?if ($this->viewParams['type'] == "gallery") :?>
	<a class="links" href="/vi/gallery/upload-photos?id=<?=$member['id']?>" style="text-color:red">Upload photos |
	<?else:?>
	<a class="links" href="/vi/archin/master/edit?type=<?=$this->viewParams['type']?>&id=<?=$member['id']?>" style="text-color:red">Edit |
	<?endif?>
	 <?php
	 if ($this->viewParams['type'] == "people") 
	 $thumb = "/public/archin/people/". $member['id'] . "/avatar.jpg";
	 else if (($this->viewParams['type'] == "project") && $member['gallery'])
	 {
	 	$nodeService = new node_Model_NodeService();
	 	$nodeTypeInfo = $nodeService->getNodeTypeInfo("gallery");
		if (!$nodeTypeInfo)
		{
			$this->renderError(null, "Node Type does not exist");
		}
		$ret = $nodeService->getNodeData($nodeTypeInfo, $member['gallery'], null);
		$gallery = $ret['node'];
		
	 	$thumb = str_replace("/original/", "/small/",$gallery['thumb']);
	 }
	 else if ($this->viewParams['type'] == "project" || $this->viewParams['type'] == "post" )
	 	$thumb = "#";
	 else if ($this->viewParams['type'] == "gallery")
	 	$thumb = $member['thumb'];
	 ?>
	 <img src="<?=$thumb?>" style="height:20px"/>
	</a>
	<?if ($this->viewParams['type'] == "gallery") :?>
	<?= $member['title']?>
	<?else:?>
	<?= $member['name_vi']?> 
	<?endif?>
	<? if ($this->viewParams['type'] == "post") :?>
	| code: <?= $member['code']?>	
	<?endif?>
	</li>
<? endforeach?>
</ul>
</div>

<?if ($this->viewParams['type'] != "post" && $this->viewParams['type'] != "gallery") :?>
<div>
<input type="button" value="Save order" id="save_order"/>
</div>
<script type="text/javascript">
$(function() {
	$("#sortable").sortable({
		'cursor' : 'crosshair'	
	});
	$("#sortable").disableSelection();
	$("#save_order").click(function(){
		ser = $('#sortable').sortable('serialize');
		$.post("/vi/archin/ajax/order?type=<?=$this->viewParams['type']?>&" + ser, null, function(json){
			if (json.success)
				alert("Success");
			else
				alert("Failed");
		}, "json");
	});
});
</script>
<?endif?>

<style type="text/css">
#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 30px; }
#sortable li span { position: absolute; margin-left: -1.3em; }

a.links
{
	color:green;
	text-color:red;
	text-decoration:none;
}
</style>
